/////// comments ///////

#include <vector>
#include "combined.h"
#include "command.h"
#include "commandTable.h"
#include "definitions.h"
#include "stringutil.h"
#include "timestamp.h"
#include "tEditHandler.h"
#include "world.h"

// TextEdit Command definitions
// (Keep in alphabetical order... it's MUCH easier)
tCmdAdd::tCmdAdd( void ) {
	setName( "+" );
	setLevel( 1 );
	setEnabled( true );
}

bool tCmdAdd::execute( Character* character, const std::string& args ) {
	tEditHandler* vh = tEditList::Instance().getHandler( character->getName() );

	vh->addLine( args );

	character->Send( vh->editWindow() );

	return true;
}

tCmdExit::tCmdExit( void ) {
	setName( "exit" );
	setLevel( 1 );
	setEnabled( true );
}

bool tCmdExit::execute( Character* character, const std::string& args ) {

	character->setTedit( false );
	tEditList::Instance().getList().remove( tEditList::Instance().getHandler( character->getName() ) );

	return true;
}

tCmdHelp::tCmdHelp( void ) {
	setName( "help" );
	setLevel( 1 );
	setEnabled( true );
}

bool tCmdHelp::execute( Character* character, const std::string& args ) {
	std::string buf;

	buf = "{CSymphony Text Editor commands{x\n\r\n\r";
	buf << " +  {w[number]{x {w[line]{x  appends text\n\r";
	buf << " -  {w[number]{x         removes a line\n\r";
	buf << " il {w[number]{x {W<line>{x  inserts text\n\r";
	buf << " rl {W<number>{x {W<line>{x  replaces a given line of text\n\r";
	buf << " exit                quits Symphony Text Editor\n\r";

	character->Send( buf );

	return true;
}

tCmdInsert::tCmdInsert( void ) {
	setName( "il" );
	setLevel( 1 );
	setEnabled( true );
}

bool tCmdInsert::execute( Character* character, const std::string& args ) {
	tEditHandler* vh = tEditList::Instance().getHandler( character->getName() );

	vh->insertLine( args );

	character->Send( vh->editWindow() );

	return true;
}

tCmdRemove::tCmdRemove( void ) {
	setName( "-" );
	setLevel( 1 );
	setEnabled( true );
}

bool tCmdRemove::execute( Character* character, const std::string& args ) {
	tEditHandler* vh = tEditList::Instance().getHandler( character->getName() );

	vh->removeLine( args );

	character->Send( vh->editWindow() );

	return true;
}

tCmdReplace::tCmdReplace( void ) {
	setName( "rl" );
	setLevel( 1 );
	setEnabled( true );
}

bool tCmdReplace::execute( Character* character, const std::string& args ) {
	tEditHandler* vh = tEditList::Instance().getHandler( character->getName() );

	vh->replaceLine( args );

	character->Send( vh->editWindow() );

	return true;
}
